package com.example.springboothomework.mapper;

import com.example.springboothomework.entity.Company;
import com.example.springboothomework.entity.dto.CompanyDTO;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import org.mapstruct.MappingTarget;

/**
 * @author chenjianhao
 * @date 2025/6/7
 *
 * 公司MapStruct映射
 */
@Mapper(componentModel = "spring")
public interface CompanyMapper {


    /**
     * DTO转Entity（忽略id，新增时自增）
     * @param dto
     * @return
     */
    @Mapping(target = "id", ignore = true)
    Company toEntity(CompanyDTO dto);

    /**
     * DTO转entity（忽略id，更新时防止ID被覆盖）
     * @param dto
     * @param entity
     */
    @Mapping(target = "id", ignore = true)
    void updateEntity(CompanyDTO dto, @MappingTarget Company entity);


}